<?php
    include_once(DAO_PATH . "/ComponentDAO.php");
    include_once(OBJECT_PATH . "/Component.php");
    include_once(OBJECT_PATH . "/Category.php");

    $dao = new ComponentDAO();

    // get list of categories (function returns ArrayObject)
    $categories = $dao->getCategoryList();

    // iterate through the ArrayObject list
    $catIterator = $categories->getIterator();
    while ($catIterator->valid())
    {
        $category = $catIterator->current();
        ?>
        <div class="form-label"><?php echo $category->getName(); ?>:</div>
        <div class="form-component">
            <select name="component[]" >
                <option value="-1"></option>
                <?php
                $components = $dao->getComponentList($category->getId());

                $compIterator = $components->getIterator();
                while ($compIterator->valid())
                {
                    $component = $compIterator->current();
                    ?>
                    <option value="<?php echo $component->getId(); ?>"><?php echo $component->getName(); ?></option>
                    <?php
                    $compIterator->next();
                }
                ?>
            </select>
        </div>
        <?php
        $catIterator->next();
    }

?>